package main

import (
	"fmt"
	"log"
	"sync"
	"time"
)

// 条件变量
// 一定由条件的修改和条件的读取判断
// 所以需要创建一个锁锁起来
var done = false

func read(name string, c *sync.Cond) {
	c.L.Lock()
	for !done {
		c.Wait()
	}
	log.Println(name, "starts reading")
	c.L.Unlock()

}

func write(name string, c *sync.Cond) {
	log.Println(name, "starts writing")
	time.Sleep(time.Second)
	c.L.Lock()
	done = true
	c.L.Unlock()
	log.Println(name, "wakes all")
	c.Broadcast()
}

func copydone() bool {
	return false
}
func copyto(c *sync.Cond) {
	for {
		c.L.Lock()

		for !copydone() {
			fmt.Println("adsfasdf")
			c.Wait()
		}
		fmt.Println("copy...")
		c.L.Unlock()

	}

}

func main() {
	// cond := sync.NewCond(&sync.Mutex{})

	// go copyto(cond)
	// cond.Signal()
	// time.Sleep(time.Second * 10)
	var i interface{} = 1
	fmt.Println(i.(string))
}
